import React, { Component } from 'react';
import { StyleSheet, View,Text } from 'react-native';

import ActionSheet from 'react-native-actionsheet'
import {takePhoto,fromAlbum} from './PhotoSelector';

export default class PhotoActionSheet extends Component {
    constructor(props) {
        super(props)
    }

    showActionSheet = ()=> {
        this.ActionSheet.show()
    }

    actionPress = (i)=> {
        if (i == 1) {
            takePhoto(this.props.onSuccess)
        } else if (i == 2) {
            fromAlbum(this.props.onSuccess)
        }
    }

    render() {
        let {title="获取一张照片"}=this.props;
        let options = ['取消', "拍照", "从相册选择..."];
        return (
            <View style={styles.wrapper}>
                <ActionSheet
                    ref={o => this.ActionSheet = o}
                    title={title}
                    options={options}
                    cancelButtonIndex={0}
                    onPress={this.actionPress}
                />
            </View>
        )
    }
}


const styles = StyleSheet.create({
    wrapper: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center'
    },
    button: {
        width: 200,
        marginBottom: 10,
        paddingTop: 15,
        paddingBottom: 15,
        textAlign: 'center',
        color: '#fff',
        backgroundColor: '#38f'
    }
})
